/* Wang Wen(Albert Wang) jawangwen@gmail.com */

#ifndef __RT_DEBUG_H__
#define __RT_DEBUG_H__

#ifdef __cplusplus
extern "C" {
#endif

#define DBG_ENABLE          1
#define DBG_DISABLE         0

#define DBG_RT_STUB_ERROR   DBG_ENABLE
#define DBG_RT_STUB_WARN    DBG_ENABLE
#define DBG_RT_STUB_TRACE   DBG_DISABLE

#define DBG_RT_REFER_ERROR  DBG_ENABLE
#define DBG_RT_REFER_WARN   DBG_ENABLE
#define DBG_RT_REFER_TRACE  DBG_DISABLE

/************************  debug for rt_stub  *********************/
#define RT_STUB_ERROR(fmt, args...) RT_DEBUG_ERROR(DBG_RT_STUB_ERROR, fmt, ##args)
#define RT_STUB_WARN(fmt, args...)  RT_DEBUG_WARN(DBG_RT_STUB_WARN, fmt, ##args)
#define RT_STUB_TRACE(fmt, args...) RT_DEBUG_TRACE(DBG_RT_STUB_TRACE, fmt, ##args)
/******************************************************************/

/************************  debug for rt_refer  ********************/
#define RT_REFER_ERROR(fmt, args...) RT_DEBUG_ERROR(DBG_RT_REFER_ERROR, fmt, ##args)
#define RT_REFER_WARN(fmt, args...)  RT_DEBUG_WARN(DBG_RT_REFER_WARN, fmt, ##args)
#define RT_REFER_TRACE(fmt, args...) RT_DEBUG_TRACE(DBG_RT_REFER_TRACE, fmt, ##args)
/******************************************************************/

#define RT_DEBUG_ERROR(enable, fmt, args...) do { \
    if(enable) {                                  \
        fprintf(stderr,                           \
                "\n[ERROR] (%s:%s:%d) "fmt"\n",   \
                __FILE__,                         \
                __FUNCTION__,                     \
                __LINE__,                         \
                ##args);                          \
    }                                             \
} while (0)

#define RT_DEBUG_WARN(enable, fmt, args...) do {  \
    if(enable) {                                  \
        fprintf(stderr,                           \
                "\n[ERROR] (%s:%s:%d) "fmt"\n",   \
                __FILE__,                         \
                __FUNCTION__,                     \
                __LINE__,                         \
                ##args);                          \
    }                                             \
} while (0)

#define RT_DEBUG_TRACE(enable, fmt, args...) do { \
    if(enable) {                                  \
        fprintf(stdout,                           \
                "\n[ERROR] (%s:%s:%d) "fmt"\n",   \
                __FILE__,                         \
                __FUNCTION__,                     \
                __LINE__,                         \
                ##args);                          \
    }                                             \
} while (0)

#ifdef __cplusplus
}
#endif

#endif /* __RT_DEBUG_H__ */

